<?php
class SearchWidget  extends CWidget{
    
	//输出字符串
	private $out = '';
    
    private $controller= '';
    
    private $action= '';

	public function init(){
        $this->controller = Yii::app()->controller->id;  
        $this->action = Yii::app()->controller->action->id; 
	}

	public function run(){
        $this->generateAd();
		echo $this->out;
	}

    public function generateAd(){
        $criteria=new CDbCriteria();
        $criteria->limit = 4;
        $criteria->offset = 0;
        $criteria->order = 'create_date DESC';
        $models = Ad::model()->findAll($criteria);
        
        $items = '';
        foreach($models as $k=>$v){
            $items .= <<<ITEM
                    <li class='span3'>
                        <div class='thumbnail'>
                            <a href='{$v->ad_url}' title='{$v->ad_title}' target='_blank' rel='nofllow'><img style='width:260px;height:13   0px;' alt='{$v->img_title}' title='{$v->img_title}' src="{$v->img_url}" alt=""></a>
                        </div>
                    </li>
ITEM;
        }

        $baseScript = Yii::app()->request->baseUrl;
        $titleString = CHtml::encode(Yii::app()->name);
        $descriptionString = CHtml::encode(Yii::app()->params['description']);
        $siteAddressString = CHtml::encode(Yii::app()->params['siteAddress']);
        $emailString = CHtml::encode(Yii::app()->params['adminEmail']);

        //javascript
        if(strtolower($category) == 'javascript'){
            $this->out .= <<<ADamazon
                <div class='ad' style='height:140px'>
                    <iframe src="http://rcm-cn.amazon-adsystem.com/e/cm?t=gowhich-23&o=28&p=48&l=ur1&category=books&banner=1AEPZHWQXT7BM3TJEYR2&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
                </div>
ADamazon;
        }else if(strtolower($category) == 'php'){//php
            $this->out .= <<<ADamazon
                <div class='ad' style='height:140px'>
                    <iframe src="http://rcm-cn.amazon-adsystem.com/e/cm?t=gowhich-23&o=28&p=48&l=ur1&category=books&banner=0N1EE2HPKAHGCPMYENR2&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
                </div>
ADamazon;
        }else if(strtolower($category) == 'ios'){//ios
            $this->out .= <<<ADamazon
                <div class='ad' style='height:140px'>
                    <iframe src="http://rcm-cn.amazon-adsystem.com/e/cm?t=gowhich-23&o=28&p=48&l=ur1&category=books&banner=1XSMN46B43MCKDMP8482&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
                </div>
ADamazon;
        }else if(strtolower($category) == 'java'){//java
            $this->out .= <<<ADamazon
                <div class='ad' style='height:140px'>
                    <iframe src="http://rcm-cn.amazon-adsystem.com/e/cm?t=gowhich-23&o=28&p=48&l=ur1&category=books&banner=05N2DAAYH5S81R9FYB82&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
                </div>
ADamazon;
        }else if(strtolower($category) == 'object-c'){//OBJECT-C  
            $this->out .= <<<ADamazon
                <div class='ad' style='height:140px'>
                    <iframe src="http://rcm-cn.amazon-adsystem.com/e/cm?t=gowhich-23&o=28&p=48&l=ur1&category=books&banner=0N2RCJX6RDQ1BWCHFD02&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
                </div>
ADamazon;
        }else if(strtolower($category) == 'python'){//python
            $this->out .= <<<ADamazon
                <div class='ad' style='height:140px'>
                    <iframe src="http://rcm-cn.amazon-adsystem.com/e/cm?t=gowhich-23&o=28&p=48&l=ur1&category=books&banner=0N1EE2HPKAHGCPMYENR2&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
                </div>
ADamazon;
        }else if(strtolower($category) == 'linux'){//LINUX  
            $this->out .= <<<ADamazon
                <div class='ad' style='height:140px'>
                    <iframe src="http://rcm-cn.amazon-adsystem.com/e/cm?t=gowhich-23&o=28&p=48&l=ur1&category=books&banner=1WWDBKWK6487YP565S82&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
                </div>
ADamazon;
        }else if(strtolower($category) == 'css' || strtolower($category) == 'html'){//HTML   css
            $this->out .= <<<ADamazon
                <div class='ad' style='height:140px'>
                    <iframe src="http://rcm-cn.amazon-adsystem.com/e/cm?t=gowhich-23&o=28&p=48&l=ur1&category=books&banner=0JDR742NFWAX3MD8F702&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
                </div>
ADamazon;
        }else if(strtolower($category) == ''){//empty
            $this->out .= <<<ADamazon
                <div class='ad' style='height:140px'>
                    <iframe src="http://rcm-cn.amazon-adsystem.com/e/cm?t=gowhich-23&o=28&p=48&l=ur1&category=books&banner=0N1EE2HPKAHGCPMYENR2&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
                </div>
ADamazon;
        }else if(strtolower($category) == ''){//not empty
            $this->out .= <<<ADamazon
                <div class='ad' style='height:140px'>
                    <iframe src="http://rcm-cn.amazon-adsystem.com/e/cm?t=gowhich-23&o=28&p=48&l=ur1&category=books&banner=0180BWJ6PCQ82M6J0Q82&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
                </div>
ADamazon;
        }
        

        
        $this->out .= <<<OUT
                <div class='ad' style='height:140px'>
                    <url class='thumbnails'>
                        $items
                    </url>
                </div>\n
                <hr>\n
OUT;
    }
}



